cmake_minimum_required(VERSION 3.12)
project(baozhu)

#set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

################################## 配置QT5环境 #################################
# 自动调用moc，uic，rcc处理qt的扩展部分
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
# 设置Qt5的cmake模块所在目录,如果不设置将使用系统提供的版本
set(CMAKE_PREFIX_PATH C:/Qt/Qt5.14.2/5.14.2/msvc2017_64/lib/cmake)
# 找到对应的qt模块，名字为qmake中QT += <name>中的name首字母大写后加上Qt5前缀
# 例如core为QtCore，你也可以去${CMAKE_PREFIX_PATH}的目录中找到正确的模块名
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
# 设置要使用的QT库
set(QT5_LIBS Qt5::Core Qt5::Widgets Qt5::Gui)

################################## 第三方库头文件配置 #################################

# --- OpenCV --- #
set(CV_INCLUDE_DIR "C:/OpenCV/opencv/build/include")

################################## 第三方库.lib文件路径 #################################
set(CV_LIB_DIR "C:/OpenCV/opencv/build/x64/vc15/lib")
################################### 第三方库.lib文件名 ##################################
IF(${CMAKE_BUILD_TYPE} STREQUAL "Release")
    set(CV_LIB opencv_world430)
ELSEIF(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
    set(CV_LIB opencv_world430d)
ENDIF()
###################################### 链接第三方库 #####################################
# --- 配置opencv --- #
include_directories(${CV_INCLUDE_DIR})
include_directories(${CV_INCLUDE_DIR}/opencv2)
link_directories(${CV_LIB_DIR})
link_libraries(${CV_LIB})

# -----------------------------------------------------------------------------------
AUX_SOURCE_DIRECTORY(./src SOURCE_DIR)

# src/MainWindow.qrc必须单独写进去，不然图片会失效
IF(${CMAKE_BUILD_TYPE} STREQUAL "Release")
    add_executable(${PROJECT_NAME} WIN32 ${SOURCE_DIR} main.cpp)
ELSEIF(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
    add_executable(${PROJECT_NAME} ${SOURCE_DIR} main.cpp)
ENDIF()

#链接静态库
target_link_libraries(${PROJECT_NAME} ${QT5_LIBS} ${CV_LIB})

#指定二进制文件位置
IF(${CMAKE_BUILD_TYPE} STREQUAL "Release")
    SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
ELSEIF(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
    SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin_debug)
ENDIF()

